<?php
//Hot, vip 
$sql = "SELECT b.* , s.title as titlesec, c.title as titlecate, ci.title as titlecity, dis.title as titledis"
	."\n FROM #__bds AS b, #__bdscategory AS c, #__bdssections AS s, #__city as ci, #__district as dis"
	."\n WHERE b.published=1 AND b.bdssection_id=s.id AND b.bdscategory_id=c.id AND b.city_id=ci.id AND b.district_id=dis.id AND (b.hot=1 OR b.vip=1)"
	."\n ORDER BY b.ordering ASC, b.id DESC LIMIT 0,20"
	;
$database->setQuery($sql);
$hot_vip = $database->loadObjectList();

$sql = "SELECT b.* , s.title as titlesec, c.title as titlecate, ci.title as titlecity, dis.title as titledis"
	."\n FROM #__bds AS b, #__bdscategory AS c, #__bdssections AS s, #__city as ci, #__district as dis"
	."\n WHERE b.published=1 AND b.bdssection_id=s.id AND b.bdscategory_id=c.id AND b.city_id=ci.id AND b.district_id=dis.id AND b.hot=0 AND b.vip=0"
	."\n ORDER BY b.ordering ASC, b.id DESC LIMIT 0,20"
	;
$database->setQuery($sql);
$rows = $database->loadObjectList();
if (count($hot_vip)>0){
?>
<!-- HOT - VIP -->
<div class="title">
	<div class="boxT1"><span style="color:red;">Bất động sản Hot - Vip</span></div>
	<div class="boxT3">Nơi đăng</div>
	<div class="boxT2">Giá</div>
	<div class="boxT3">Ngày đăng</div>
	<div class="boxT4">Ảnh</div>
</div>
	<?php for ($i=0; $i<count($hot_vip); $i++){
		$link = "index.php?option=com_bds&task=view&id=".$hot_vip[$i]->id;
		//$link = "component/option,com_bds/task,view/id,".$rows[$i]->id."-".$rows[$i]->title_alias.".html";
		if ($hot_vip[$i]->img!=''){
			$image = $mosConfig_live_site.'/templates/html_tcland/images/HouseIcon.png';
		}else{
			$image = $mosConfig_live_site.'/templates/html_tcland/images/HouseIconH.png';
		}
		if ($hot_vip[$i]->price==0){
			$TEXTPRICE = "Đang cập nhật giá";
		}else{
			$TEXTPRICE = number_format($hot_vip[$i]->price,0,',','.');
		}
		if ($i==(count($hot_vip)-1)){
			$style = ' style="border-bottom:1px solid #C0C0C0;"';
		}else{
			$style = '';
		}
		//Show Icon
		if ($hot_vip[$i]->vip==1){
			$showIcon = '<img src="'.$mosConfig_live_site.'/images/icon/vip.gif" border="0" />';
		}else{
			$showIcon = '<img src="'.$mosConfig_live_site.'/images/icon/icon-hot.gif" border="0" />';
		}
	?>
	<div class="lscontent"<?php echo $style;?>>
		<div class="box1">
		Mã tin : <?php echo $hot_vip[$i]->code;?> <?php echo $showIcon;?><br />
		<a href="<?php echo $link;?>"><?php echo $hot_vip[$i]->title;?></a><b style="color:#ff7700; padding-left:5px;">(<?php echo number_format($hot_vip[$i]->view,0,',','.');?> <span style="font-weight:normal; color:#999;">lượt xem</span>)</b><br />
		<?php echo $hot_vip[$i]->dien_tich;?> m2
		</div>
		<div class="box3"><?php echo $hot_vip[$i]->titlecity;?></div>
		<div class="box2"><?php echo $TEXTPRICE;?> <b style="color:red;"><?php echo $hot_vip[$i]->menh_gia;?></b></div>
		<div class="box3"><?php echo unFormatDate($hot_vip[$i]->createdate,"d/m/Y");?></div>
		<div class="box4"><a href="#"><img src="<?php echo $image;?>" border="0" /></a></div>
	</div>
	<?php 
	}
}
if (count($rows)>0){
?>
<!-- NORMAL -->
<div class="title">
	<div class="boxT1"><span>Thông tin bất động sản</span></div>
	<div class="boxT3">Nơi đăng</div>
	<div class="boxT2">Giá</div>
	<div class="boxT3">Ngày đăng</div>
	<div class="boxT4">Ảnh</div>
</div>
	<?php for ($i=0; $i<count($rows); $i++){
		$link = "index.php?option=com_bds&task=view&id=".$rows[$i]->id;
		//$link = "component/option,com_bds/task,view/id,".$rows[$i]->id."-".$rows[$i]->title_alias.".html";
		if ($rows[$i]->img!=''){
			$image = $mosConfig_live_site.'/templates/html_tcland/images/HouseIcon.png';
		}else{
			$image = $mosConfig_live_site.'/templates/html_tcland/images/HouseIconH.png';
		}
		if ($rows[$i]->price==0){
			$TEXTPRICE = "Đang cập nhật giá";
		}else{
			$TEXTPRICE = number_format($rows[$i]->price,0,',','.');
		}
		if ($i==(count($rows)-1)){
			$style = ' style="border-bottom:1px solid #C0C0C0;"';
		}else{
			$style = '';
		}
		//New Icon
		$nows = mktime(0,0,0,date("m"),date("d"),date("Y"));
		$ngay_nhap = mktime(0,0,0,unFormatdate($rows[$i]->createdate,"m"),unFormatdate($rows[$i]->createdate,"d"),unFormatdate($rows[$i]->createdate,"Y"));
		$days = ($nows - $ngay_nhap)/86400;
		if ($days>0){
			$showIcon = '';
		}else{
			$showIcon = '<img src="'.$mosConfig_live_site.'/images/icon/New_icons_10.gif" border="0" />';
		}
	?>
	<div class="lscontent"<?php echo $style;?>>
		<div class="box1">
		Mã tin : <?php echo $rows[$i]->code;?> <?php echo $showIcon;?><br />
		<a href="<?php echo $link;?>"><?php echo $rows[$i]->title;?></a><b style="color:#ff7700; padding-left:5px;">(<?php echo number_format($rows[$i]->view,0,',','.');?> <span style="font-weight:normal; color:#999;">lượt xem</span>)</b><br />
		<?php echo $rows[$i]->dien_tich;?> m2
		</div>
		<div class="box3"><?php echo $rows[$i]->titlecity;?></div>
		<div class="box2"><?php echo $TEXTPRICE;?> <b style="color:red;"><?php echo $rows[$i]->menh_gia;?></b></div>
		<div class="box3"><?php echo unFormatDate($rows[$i]->createdate,"d/m/Y");?></div>
		<div class="box4"><a href="#"><img src="<?php echo $image;?>" border="0" /></a></div>
	</div>
	<?php 
	}
}	
?>